package cn.dankal.lequ.ui.fragment.comprehensive_fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.dankal.lequ.R;
import cn.dankal.lequ.commom.adapter.BaseAdapter.ViewHolder;
import cn.dankal.lequ.commom.adapter.BaseAdapter.recyclerview.CommonAdapter;
import cn.dankal.lequ.ui.activity.BangdanActivity;
import cn.dankal.lequ.ui.activity.FirstGameActivity;
import cn.dankal.lequ.ui.activity.GameDetailsActivity;
import cn.dankal.lequ.ui.activity.HotGameActivity;

/**
 * Created by 苏彬 on 2016/4/16.
 * Edited by Fred on 2016/5/1
 */
//综合
public class CompreFragment extends Fragment {
    @Bind(R.id.recyclerview)
    RecyclerView id_home_tab_recyclerview;
    LinearLayoutManager linearLayoutManager;


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.recyclerview, container, false);
        ButterKnife.bind(this, view);
        return view;
    }


    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initRecyclerView();
    }

    private void initRecyclerView() {
        linearLayoutManager = new LinearLayoutManager(getActivity());
        id_home_tab_recyclerview.setLayoutManager(linearLayoutManager);
        id_home_tab_recyclerview.setHasFixedSize(true);
        List<Integer> mDatas = new ArrayList<>();
        mDatas.add(1);
        mDatas.add(2);
        mDatas.add(3);
        mDatas.add(4);
        id_home_tab_recyclerview.setAdapter(new CommonAdapter<Integer>(getActivity(), R.layout.item_currency_compre, mDatas) {
            @Override
            public void convert(ViewHolder holder, final Integer integer) {
                holder.setImageResource(R.id.iv_poster_top, R.mipmap.huoying);
                holder.setImageResource(R.id.iv_poster_right, R.mipmap.biaoche);
                holder.setImageResource(R.id.iv_poster_bottom, R.mipmap.huoying);
                holder.setImageResource(R.id.iv_poster_left, R.mipmap.haizu);
                holder.setText(R.id.tv_compre_name, "榜单");
                holder.setImageResource(R.id.iv_compre_icon, R.mipmap.homepage_list);
                holder.setOnClickListener(R.id.iv_poster_top, new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Intent intent = new Intent(CompreFragment.this.getActivity(), GameDetailsActivity.class);
                        startActivity(intent);
                    }
                });
                holder.setOnClickListener(R.id.all_more, new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        if (integer == 1) {
                            Intent intent = new Intent(CompreFragment.this.getActivity(), BangdanActivity.class);
                            startActivity(intent);
                        } else if (integer == 2) {
                            Intent intent = new Intent(CompreFragment.this.getActivity(), HotGameActivity.class);
                            startActivity(intent);
                        } else {
                            Intent intent = new Intent(CompreFragment.this.getActivity(), FirstGameActivity.class);
                            startActivity(intent);
                        }
                    }
                });

            }
        });

    }

}
